package com.ruoyi.controller;

import com.camp.domain.CUser;
import com.camp.domain.CYd;
import com.camp.domain.Facility;
import com.camp.domain.Facilitytype;
import com.camp.service.ICUserService;
import com.camp.service.ICYdService;
import com.camp.service.IFacilityService;
import com.camp.service.IFacilitytypeService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.dmain.MessageAO;
import com.ruoyi.dmain.Ydmap;
import com.ruoyi.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import oshi.util.Util;

import java.util.ArrayList;
import java.util.List;

//import static com.ruoyi.service.impl.WxLoginService.threadLocal;

@Anonymous
@RestController
@RequestMapping("/ydmessage")
public class Yingdi {
    @Autowired
    private ThreadLocalUtil threadLocalUtil;
    @Autowired
    private ICYdService icYdService;
    @Autowired
    private ICUserService icUserService;
    @Autowired
    private IFacilityService iFacilityService;
    @Autowired
    private IFacilitytypeService iFacilitytypeService;
    //新增营地信息
    @PostMapping("/savecamp")
    public AjaxResult savecamp(@RequestBody CYd cYd){
        System.out.println("123123123123");
        System.out.println(cYd);
        int i = icYdService.insertCYd(cYd);
        if (i!=0){
            return AjaxResult.success("新增成功");
        }
        System.out.println("2312312312");
        return AjaxResult.error("填写信息有误，添加失败");
    }

    //查询所有营地的经纬度和名称
    @GetMapping("/ydcamp")
    public AjaxResult camp(){
        Ydmap ydmap=new Ydmap();
        List<Ydmap> ydmaps=new ArrayList<>();
        List<CYd> cYds = icYdService.selectCYdList(new CYd());
        System.out.println(cYds);
        for (CYd cYd:cYds){
            Ydmap ydmap1=new Ydmap();
           ydmap1.setTitle( cYd.getYdName());
           ydmap1.setLongitude( Double.valueOf((cYd.getYdJingdu())));
           ydmap1.setLatitude(Double.valueOf(cYd.getYdWeidu()));
           ydmaps.add(ydmap1);
        }
        return AjaxResult.success(ydmaps);
    }



    //修改个人信息
    @PostMapping("/xiugai")
    public AjaxResult xiugaimesage(@RequestBody MessageAO messageAO){
        System.out.println("2222222222222222222333333333333");
        System.out.println(messageAO);
        CUser cUser=new CUser();
        cUser.setUserId(messageAO.getId());
        cUser.setImg(messageAO.getAvatarUrl());
        cUser.setUsername(messageAO.getName());


//        String value = threadLocalUtil.get();

//        cUser.setUserId(value);
        System.out.println("wkkkkkkkkkkkkkk");
        System.out.println(cUser);

        int i = icUserService.updateCUser(cUser);

        System.out.println(i);
        if (i==1){
            return AjaxResult.success(messageAO);
        }
        return AjaxResult.error("修改个人信息失败");

    }
//根据用户类型查询所有营地信息
    @GetMapping("/ydxiangqing")
        public AjaxResult ydxiangqing( CYd cYd){
        System.out.println("111111111111111");
        System.out.println(cYd);
//        CYd cyd=new CYd();

        List<CYd> cYds = icYdService.selectCYdList(cYd);

        return AjaxResult.success(cYds);
    }

    //删除营地
    @DeleteMapping("/{ydIds}")
    public AjaxResult remove(@PathVariable String[] ydIds)
    {
        return AjaxResult.success(icYdService.deleteCYdByYdIds(ydIds));
    }
//查询设施
    @GetMapping("/listsheshi")
    public AjaxResult listshebei(){
        List<Facility> facilities = iFacilityService.selectFacilityList(new Facility());
        return AjaxResult.success(facilities);
    }
//查询设施类型
    @GetMapping("/sheshitype")
    public AjaxResult sheshileixing(){
        List<Facilitytype> facilitytypes = iFacilitytypeService.selectFacilitytypeList(new Facilitytype());
        return AjaxResult.success(facilitytypes);
    }
}
